package com.jxsd.edu.cn.struts2.daoImpl;

import java.util.ArrayList;
import java.util.List;

import com.jxsd.edu.cn.struts2.dao.PublishGoodAttributeDao;
import com.jxsd.edu.cn.struts2.models.PublishGoodAttribute;
import com.jxsd.edu.cn.tools.ResultList;
import com.jxsd.edu.cn.tools.Template;

public class PublishGoodAttributeDaoImpl implements PublishGoodAttributeDao {

	@Override
	public void addAttribute(PublishGoodAttribute attribute) 
	{
		

	}

	@Override
	public void deleteAttribute(String attributeId) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<PublishGoodAttribute> getAttributes(String publishId) {
		List<PublishGoodAttribute>  list=null;
		String  sql="select  attributeName,attributeValue  from  publishgoodattribute  where  publishId=?";
		Object[]  params={publishId};
		ResultList<PublishGoodAttribute>  hander=new  ResultList<PublishGoodAttribute>();
		try {
			list=hander.handler(sql, params, PublishGoodAttribute.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

		@Override
	public List<PublishGoodAttribute> getHotAttributes(String publishId) {
		List<PublishGoodAttribute>  list1=null;
		List<PublishGoodAttribute>  list2=null;
		String  sql1="select   attributeName,attributeValue  from   hotCataAttriView  where  publishId=?";
		String  sql2="select   attributeName,attributeValue  from   hotCataAttriView  where  publishId=?";
		Object[]  params={publishId};
		ResultList<PublishGoodAttribute>  hander=new  ResultList<PublishGoodAttribute>();
		try {
			list1=hander.handler(sql1, params, PublishGoodAttribute.class);
			list2=hander.handler(sql2, params, PublishGoodAttribute.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(list2!=null)
		for(PublishGoodAttribute    hot:list2)
		{
			list1.add(hot);
		}
		return list1;
	}

		@Override
		public void updateGoodAttri(String  publishID,List<PublishGoodAttribute> list) {
			String  sql="update  publishgoodattribute   attributeName=?,attributeValue=?  where  publishId=?";
			List<Object[]>  listParams=new  ArrayList<Object[]>();
			for(PublishGoodAttribute  attri:list)
			{
				Object[]  params={attri.getAttributeName(),attri.getAttributeValue(),publishID};
				
				listParams.add(params);
			}
			Template  t=new  Template();
			t.batchUpdate(sql, listParams);
		}

		@Override
		public void updatePubMsgAttris(String  publishID,List<PublishGoodAttribute> list)
		{
			String  sql="insert  into  publishgoodattribute(publishID,attributeName,attributeValue)  values(?,?,?)";
			List<Object[]>  listParams=new  ArrayList<Object[]>();
			for(PublishGoodAttribute  attri:list)
			{
				Object[]  params={publishID,attri.getAttributeName(),attri.getAttributeValue()};
				
				System.out.println("PublishGoodAttributeDaoImpl:updatePubMsgAttris"+attri.getAttributeName());
				System.out.println("PublishGoodAttributeDaoImpl:updatePubMsgAttris"+attri.getAttributeValue());
				
				listParams.add(params);
			}
			Template  t=new  Template();
			t.batchUpdate(sql, listParams);
			
		}

		@Override
		public void deletePubMsgAttri(String publishID) {
			String  sql="delete  from   publishgoodattribute  where   publishId=? ";
			Object[]  params={publishID};
			Template  t=new  Template();
			t.update(sql, params);
		}

}
